package com.saint.news.Utils;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.text.TextUtils;
import android.util.Log;
import android.widget.ImageView;
import android.widget.Toast;

import com.bumptech.glide.Glide;
import com.saint.news.MainActivity;

/**
 * Created by Administrator on 2018/3/12.
 */

public class GlideUtil {
    public static void loadImg(Context context, String imgUrl, ImageView imgView, Drawable placeholder, Drawable error) {
        if (imgUrl.startsWith("/")) {
            imgUrl = MainActivity.url + imgUrl.substring(1, imgUrl.length());
        } else {
            imgUrl = MainActivity.url + imgUrl;
        }
        Log.e("TAG", "当前加载图片：" + imgUrl);
        Glide.with(context)
                .load(imgUrl)
                .placeholder(placeholder)
                .error(error)
                .into(imgView);
    }

    public static void loadImg(Context context, String imgUrl, ImageView imgView, Drawable loading) {
        if (TextUtils.isEmpty(imgUrl)) {
            Toast.makeText(context, "当前图片地址为空", Toast.LENGTH_SHORT).show();
            return;
        }
        if (imgUrl.startsWith("/")) {
            imgUrl = MainActivity.url + imgUrl.substring(1, imgUrl.length());
        } else {
            imgUrl = MainActivity.url + imgUrl;
        }
        Log.e("TAG", "当前加载图片：" + imgUrl);
        Glide.with(context)
                .load(imgUrl)
                .placeholder(loading)
                .into(imgView);
    }
    public static void loadImg(Context context, String imgUrl, ImageView imgView) {
        if (TextUtils.isEmpty(imgUrl)) {
            Toast.makeText(context, "当前图片地址为空", Toast.LENGTH_SHORT).show();
            return;
        }
        if (imgUrl.startsWith("/")) {
            imgUrl = MainActivity.url + imgUrl.substring(1, imgUrl.length());
        } else {
            imgUrl = MainActivity.url + imgUrl;
        }
        Log.e("TAG", "当前加载图片：" + imgUrl);
        Glide.with(context)
                .load(imgUrl)
                .into(imgView);
    }

    public static void loadImg(Context context, int resId, ImageView imgView) {
        Glide.with(context)
                .load(resId)
                .into(imgView);
    }
}
